<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">添加客户信息</h3>
                </div>
                <form id="chlientAdd" class="form-horizontal" role="form">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="site" class="col-sm-2 control-label">网站：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="site" class="form-control" name="site"
                                       placeholder="网站">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="domain" class="col-sm-2 control-label">域名：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="domain" class="form-control" name="domain"
                                       placeholder="域名">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="type" class="col-sm-1 control-label">分类：</label>
							  <div class="col-sm-8 ">
                             <select id="type" name="type" class="form-control select2">
                               	<option value="1">小说</option>
                                <option value="2">文章</option>
                                <option value="3">视频</option>
                                <option value="4">图片</option>
                                <option value="5">搞笑</option>
                                <option value="6">漫画</option>
                                <option value="7">站群</option>
                                <option value="8">其他</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="flow" class="col-sm-1 control-label">流量：</label>
							  <div class="col-sm-8 ">
                             <select id="flow" name="flow" class="form-control select2">
                               	<option value="1">10000以下</option>
                                <option value="2">10000-20000</option>
                                <option value="3">30000-50000</option>
                                <option value="4">50000以上</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="QQ" class="col-sm-2 control-label">QQ：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="QQ" class="form-control" name="QQ"
                                       placeholder="QQ">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="email" class="col-sm-2 control-label">邮箱：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="email" class="form-control" name="email"
                                       placeholder="邮箱">
                            </div>
                        </div>
                       <br>
                        <div class="form-group">
                            <label for="phone" class="col-sm-2 control-label">电话：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="phone" class="form-control" name="phone"
                                       placeholder="电话">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="remark" class="col-sm-2 control-label">备注：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="remark" class="form-control" name="remark"
                                       placeholder="备注">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="testResult" class="col-sm-1 control-label">是否测试：</label>
							  <div class="col-sm-8 ">
                             <select id="testResult" name="testResult" class="form-control select2">
                               	<option value="1">已测试</option>
                                <option value="2">测试中</option>
                                <option value="3">未测试</option>
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="form-group">
							<label for="userId" class="col-sm-1 control-label">商务负责人：</label>
							  <div class="col-sm-8 ">
                             <select id="userId" name="userId" class="form-control select2">
                             </select>
                             </div>
                        </div>
                        <br>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
	function selectUserId(){
		$.ajax({
			type:"post",
			url:"<%=path%>/user/findBusiness",
			dataType:"json",
			success: function(data){
				var optionstring = "";
				$.each(data.userList, function(i,val){
					 optionstring += "<option value=\"" + val.id + "\" >" + val.businessName + "</option>";
				});
				 $("#userId").html("<option value='-1'>请选择...</option> "+optionstring);  
			   }
			});
	}

    $(function () {
    	selectUserId();
        $('#chlientAdd').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
            	site: {
                    message: '网站验证失败',
                    validators: {
                        notEmpty: {
                            message: '网站不能为空'
                        },
                    }
                },
                domain: {
                    message: '域名验证失败',
                    validators: {
                        notEmpty: {
                            message: '域名不能为空'
                        }
                    }
                },
                email: {
                    message: '邮箱地址验证失败',
                    validators: {
                        notEmpty: {
                            message: '邮箱地址不能为空'
                        },
                        emailAddress: {
                            message: '邮箱地址格式有误'
                        }
                    }
                },    
            	QQ: {
                    message: 'QQ验证失败',
                    validators: {
                        numeric: {
                        	message: 'QQ只能输入数字'
                        } 
                    }
                },
                userId: {
                    message: '商务负责人验证失败',
                    validators: {
                        callback: {  
                            message: '请选择商务负责人',  
                            callback: function(value, validator) { 
                            	if(value==-1){
                            		return false;
                            	}else{
                            		return true;
                            	}
                            }  
                        }
                    }
                },
                phone: {
                    message: '电话验证失败',
                    validators: {
                        stringLength: {
                            min: 11,
                            max: 11,
                            message: '请输入11位手机号码'
                        },
                        regexp: {
                            regexp: /^1[3|5|8]{1}[0-9]{9}$/,
                            message: '请输入正确的手机号码'
                        }
                    }
                },
                flow: {
                    message: '流量验证失败',
                    validators: {
                        callback: {  
                            message: '请选择流量',  
                            callback: function(value, validator) { 
                            	if(value==-1){
                            		return false;
                            	}else{
                            		return true;
                            	}
                            }  
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            save();
        });
    });

    function save() {
        $.post("<%=path%>/client/addClient",
            $("#chlientAdd").serialize()
            , function (data) {
                if (data.missage == "success") {
                    modalMsg("新增成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "userNameRepeat"){
                	 modalMsg("新增失败", "userNameRepeat");
                }else{
                	 modalMsg("更新失败", "error");
                }

            }
        );
    }
    
</script>
</body>
</html>